package jdk.thread.lock;


/**
 * Object类的wait/notify/notifyAll的测试地
 */
public class WaitNotifyTest {

    public static void main(String[] args) throws InterruptedException {


        Thread thread1 = new Thread(new Runnable() {
            @Override
            public synchronized void run() {
                System.out.println("wait()...before");
                /**
                 * 调用对象的wait/notify时，一定要先获取对象的锁，否则报错IllegalMonitorStateException
                 */
                try {
                    this.wait(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println("wait()...after");
            }
        });

        System.out.println(thread1.getState());
        thread1.start();
        System.out.println(thread1.getState());
        Thread.sleep(1000);
        System.out.println(thread1.getState());
        Thread.sleep(2000);
        System.out.println(thread1.getState());

    }
}
